package cn.jantd.modules.activiti.util;

/**
 * @ProjectName: trial-training-flow-boot-parent
 * @Package: cn.jantd.modules.activiti.util
 * @ClassName: CustomUserTaskJsonConverter
 * @Author: admin
 * @Description:
 * @Date: 2020/8/11 16:58
 * @Version: 1.0
 */

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.activiti.bpmn.model.BaseElement;
import org.activiti.bpmn.model.CustomProperty;
import org.activiti.bpmn.model.FlowElement;
import org.activiti.bpmn.model.UserTask;
import org.activiti.editor.language.json.converter.UserTaskJsonConverter;

import java.util.Map;

public class CustomUserTaskJsonConverter extends UserTaskJsonConverter {

    @Override
    protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
        FlowElement flowElement = super.convertJsonToElement(elementNode,modelNode,shapeMap);
        UserTask userTask = (UserTask)flowElement;
        CustomProperty customProperty = new CustomProperty();
        //添加扩展属性的名称对应stencilset.json里定义的id
        customProperty.setName("responsibledepartment");
        customProperty.setSimpleValue(this.getPropertyValueAsString("responsibledepartment",elementNode));
        CustomProperty customProperty1 = new CustomProperty();
        customProperty1.setName("responsiblepost");
        customProperty1.setSimpleValue(this.getPropertyValueAsString("responsiblepost",elementNode ));
        CustomProperty customProperty2 = new CustomProperty();
        customProperty2.setName("forms");
        customProperty2.setSimpleValue(this.getPropertyValueAsString("forms",elementNode ));
        userTask.getCustomProperties().add(customProperty);
        userTask.getCustomProperties().add(customProperty1);
        userTask.getCustomProperties().add(customProperty2);
        return userTask;
    }

    @Override
    protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
        super.convertElementToJson(propertiesNode,baseElement);
    }
}
